package beikai.com.assistant.common.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

/**
 * @program: electricity-assistant
 * @author: xiaobei
 * @create: 2021-12-27 00:08
 * @description:
 **/
public class DateUtil {

    public static final String YEAR_MONTH = "yyyy-MM";
    public static final String YEAR_MONTH_DAY_HOUR_MINUTES_SECOND = "yyyy-MM-dd HH:mm:ss";

    public static String getStringDate(LocalDateTime localDateTime,String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        return localDateTime.format(dateTimeFormatter);
    }

    public static LocalDate getLocalDate(String localDate, String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        return YearMonth.parse(localDate,dateTimeFormatter).atEndOfMonth();
    }
}
